<%layout("/common/_layout.html"){ %>
<%#ajax userTable:{%>
<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">系统管理</strong>
    /
    <small>资费业务管理</small>
  </div>
</div>
<form class="am-form" id="list-form" action="${base}/blankcardreport/list" method="post">
  <div class="am-g">
    <div class="am-u-sm-12">
      <table class="am-table am-table-bordered am-table-radius table-main am-padding-0">
        <tbody>
          <tr>
            <th class="am-text-middle">网点名称</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="site_name" class="am-form-field am-input-sm" value="${site_name!}">
                <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
              </div>
            </td>
          </tr>
          <tr>
            <td colspan="4">
              <div align='right'>
                <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="submit-btn">搜索</button>
                <button id="export" name="export" type="button"  class="am-btn am-btn-default am-btn-sm am-text-secondary">导出</button>
                <input type="hidden" class="am-input-sm"  id="isExport" name="isExport" value="0"/>
              </div>
            </td>
          </tr>
           <tr id='downloadAlertZone' style="display:none">
            <td colspan="4">
              <div id='downloadAlert' class="am-alert am-alert-warning" data-am-alert>
                <p id="downloadAlertMsg">导出失败</p>
              </div>
            </td>
          </tr>
          <tr id="download" style="display:none">
            <td colspan="4">
              <div align='center'>
                <a id="downloadlink" href="#">导出成功，点击下载</a>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</form>
<div class="am-g">
  <div class="am-u-sm-12">
    <div class="am-scrollable-horizontal">
      <table class="am-table am-table-striped am-table-hover table-main">
        <thead>
          <tr class="am-text-nowrap">
            <th class="table-title">区县分公司</th>
            <th class="table-title">平台名称</th>
            <th class="table-title">网点名称</th>
            <th class="table-title">渠道编码</th>
            <th class="table-title">网点类型</th>
            <th class="table-title">白卡买断量</th>
            <th class="table-title">写卡量</th>
            <th class="table-title">白卡剩余量</th>
          </tr>
        </thead>
        <tbody>
          <%for(list in pager.list!){%>
          <tr>
            <td>${list.parentname!}</td>
            <td>${list.parentname!}</td>
            <td>${list.DisplayName!}</td>
            <td>${list.NumCode!}</td>
            <td>${list.class_name!}</td>
            <td>${list.SIMCardCount!0}</td>
            <td>${list.used!0}</td>
            <td>${list.freeCount!}</td>
          </tr>
          <%}%></tbody>
      </table>
    </div>
    <div class="am-cf">
      <!-- 分页 -->
      <%if (pager.list.~size >
      0){%>
      <div class="am-fr">
        <% include("/admin/common_pager.tpl"){}%></div>
      <%}else{%>
      <div class="am-kai">
        <h3>没有找到任何记录!</h3>
      </div>
      <%}%></div>
    <%}%></div>
</div>
<script type="text/javascript">
  $(function() {
    //搜索
    var keywordsObj = {};
    function setKeyWords(){
      if($("#site_name").val())
        keywordsObj.site_name = $("#site_name").val();
      var keywords = "";
      if(!$.isEmptyObject(keywordsObj)){
        keywords = JSON.stringify(keywordsObj);
      }
      console.log("keywords = "+ keywords);
      $("#keywords").val(keywords);
    }

    $("#submit-btn").on("click",function(){
      setKeyWords();
      $("#isExport").val("0");
      $("#list-form").submit();
    });

    // 导出预约信息
    $("#export").on("click",function(){
      $('#download').hide();
      $('#downloadAlertZone').hide();
      //loading层
      var index = parent.layer.load(0, {
          shade: [0.1,'#fff'] //0.1透明度的白色背景
      });
      setKeyWords();
      $("#isExport").val("1");
      //$("#list-form").submit();
      var formParam = $("#list-form").serialize();//序列化表格内容为字符串
      console.log('formParam='+formParam);
      $.ajax({
        type:'post',
        url:'${base}/blankcardreport/list',
        data:formParam,
        success:function(data){
          console.log(data);
          if(data.status==1){
             $('#downloadlink').text(data.message);
             $('#downloadlink').attr('href',data.url);
             $('#download').show();
          }else{
             $('#downloadAlertMsg').text(data.message);
             $('#downloadAlertZone').show();
          }
          parent.layer.close(index);
        },
        error: function() {
           parent.layer.close(index);
        }
      });
    });
    $('#downloadAlert').on('closed.alert.amui', function() {
      $('#downloadAlertZone').hide();
    });
  });
</script>
<%}%>
